package com.intct.hbase.dml.impl;

import com.intct.hbase.dml.AbsDMLSerivce;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;

/**
 * @author gufg
 * @since 2025-09-29 16:20
 */
public class GetData extends AbsDMLSerivce {
    @Override
    public void execCommand(Table table) {
        // 执行查询
        Get get = new Get("1001".getBytes());

        // 所有版本
        get.readAllVersions();

        // 指定列族

        Result result = null;
        try {
            result = table.get(get);
            Cell[] cells = result.rawCells();

            for (Cell cell : cells) {
                String rowkey = new String(CellUtil.cloneRow(cell));
                String family = new String(CellUtil.cloneFamily(cell));
                String qualifier = new String(CellUtil.cloneQualifier(cell));
                String value = new String(CellUtil.cloneValue(cell));
                System.out.println("rowkey : " + rowkey + ";family : " + family + ";qualifier : " + qualifier + ";value : " + value);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws IOException {
        new GetData().start("intct85", "t3");
    }
}
